﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Charting;
using BSCMFF.Core.BusinessLayer;

namespace BSCMFF.Web.UserControls.Evaluation
{
    public partial class BonusSigmoid : System.Web.UI.UserControl
    {
        public double PublicValueA
        {
            get
            {
                return (double)RadNumericTextBoxA.Value;
            }
            set
            {
                RadNumericTextBoxA.Value = value;
            }
        }

        public double PublicValueB
        {
            get
            {
                return (double)RadNumericTextBoxB.Value;
            }
            set
            {
                RadNumericTextBoxB.Value = value;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (((CheckBox)this.Parent.FindControl("CheckBoxReward")).Checked == false)
            {
                return;
            }
            if (((CheckBox)this.Parent.FindControl("CheckBoxPKPIs")).Checked == false)
            {
                this.Visible = false;
            }
            else
            {
                this.Visible = true;
            }

            if (!IsPostBack)
            {
                RadChart1.RemoveAllSeries();
            }

            if (RadChart1.Series.Count > 0)
            {
                RadButtonClear.Visible = true;
            }
            else
            {
                RadButtonClear.Visible = false;
            }

            if (RadChart1.Series.Count > 3)
            {
                RadButtonTry.Visible = false;
            }
            else
            {
                RadButtonTry.Visible = true;
            }

            //int[,] data = new int[,]{{0,0}, {1,1},{2,3}};

            ChartSeries chs = new ChartSeries();
            chs.Type = ChartSeriesType.Spline;

            chs.Appearance.LabelAppearance.Visible = false;

            //chs.PlotArea.XAxis.AddRange(0, 120, 10);



            //int[] data = new int[] { 0, 1, 2, 2, 3, 4, 5, 6, 7, 8, 10, 13, 15, 20 };
            List<double> data = new List<double>();
            for (int i = 0; i < 100; ++i)
            {
                double vysledok = SigmoidHelper.Sigmoid(i, (double)RadNumericTextBoxA.Value, (double)RadNumericTextBoxB.Value);
                //data.Add(vysledok);
                ChartSeriesItem chi = new ChartSeriesItem();
                chi.YValue = vysledok;
                chs.Items.Add(chi);
            }
            RadChart1.Series.Add(chs);
            chs.PlotArea.XAxis.LabelStep = 5;
            chs.PlotArea.XAxis.MinValue = 0;
            chs.PlotArea.XAxis.AxisLabel.TextBlock.Text = "Performance";
            chs.Name = RadNumericTextBoxA.Value.ToString() + " - " + RadNumericTextBoxB.Value.ToString();
            chs.PlotArea.XAxis.Appearance.LabelAppearance.Visible = true;
            //chs.PlotArea.YAxis.
            //chs.PlotArea.YAxis. //.TextBlock.Text = "Bonus (%)";
            //RadChart1.DataSource = data;
            //RadChart1.DataBind();

        }

        //private double Sigmoid(int i)
        //{
        //    //10*(1/(1+euler^(-(x-4))))

        //    //new 100*(1/(1+(euler)^((-(x-50))/10)))

        //    double A = (double)RadNumericTextBoxA.Value;
        //    double B = (double)RadNumericTextBoxB.Value;
        //    double e = 2.71828182845904523536;

        //    return 100 * (1 / (1 + Math.Pow(e, (-1 * (i - A) / B))));
        //}

        protected void RadButtonClear_Click(object sender, EventArgs e)
        {
            RadChart1.RemoveAllSeries();
        }
    }
}